package com.siteseat.common.foundation;

import org.apache.log4j.Logger;

/**
 * 
 * 
 */
public class ObjectLogger {

  private Logger internal;
  
  private String objectName        = "";

  private String nameSection = "";

  /**
   * @param clazz
   */
  @SuppressWarnings( "unchecked" )
  public ObjectLogger( Class clazz ) {
    internal = Logger.getLogger( clazz );
  }

  /**
   * @param clazz
   * @param objectName
   */
  @SuppressWarnings( "unchecked" )
  public ObjectLogger( Class clazz, String objectName ) {
    this( clazz );
    setObjectName( objectName );
  }

  /**
   * Gets the name
   * 
   * @return the name
   */
  public String getObjectName() {
    return objectName;
  }

  /**
   * Sets the name
   * 
   * @param name
   *          the name to set
   */
  public void setObjectName( String name ) {
    this.objectName = ( name == null ) ? "no-name" : name;
    this.nameSection = '{' + this.objectName + "}: ";
  }

  /**
   * Gets the nameSection
   * 
   * @return the nameSection
   */
  public String getNameSection() {
    return nameSection;
  }

  /**
   * @param message
   */
  public void info( String message ) {
    internal.info( getNameSection() + message );
  }
  
  /**
   * @param message
   */
  public void debug( String message ) {
    internal.debug( getNameSection() + message );
  }

  /**
   * @param message
   */
  public void warn( String message ) {
    internal.warn( getNameSection() + message );
  }

  /**
   * @param message
   */
  public void warn( String message, Exception e ) {
    internal.warn( getNameSection() + message, e );
  }

  /**
   * @param message
   */
  public void error( String message ) {
    internal.error( getNameSection() + message );
  }

  /**
   * @param message
   */
  public void error( String message, Exception e ) {
    internal.error( getNameSection() + message, e );
  }

}
